package org.UserHouse.Servlet;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.UserHouse.Dao.Imp.UserDaoImp;
import org.UserHouse.Dao.UserDao;
import org.UserHouse.entity.User;

import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author bin
 * @date 2024-11-29
 */
@WebServlet("/SelectName.do")
public class SelectByUnameServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=UTF-8");

        PrintWriter out = resp.getWriter();
        String Uname = req.getParameter("Uname");
        Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd").create();

        UserDao userDao = new UserDaoImp();
        User user = userDao.selectByUname(Uname);
        String json = gson.toJson(user);
        out.println(json);

        out.flush();
        out.close();
    }
}
